#include <stdio.h>
#include <pthread.h>

pthread_mutex_t mutex1;
pthread_cond_t cond1;
pthread_mutex_t mutex2;
pthread_cond_t cond2;

void* func1(void * arg){
    
    printf("A\n");
    
    pthread_cond_signal(&cond2); //唤醒线程2
    
    pthread_cond_wait(&cond1,&mutex1);
    printf("C\n");

    return NULL;

}

void* func2(void * arg){

    pthread_cond_wait(&cond2,&mutex2);
    printf("B\n");
    pthread_cond_signal(&cond1); //唤醒线程1

    return NULL;
    
}

int main()
{
    pthread_mutex_init(&mutex1,NULL);
    pthread_cond_init(&cond1,NULL);
    pthread_mutex_init(&mutex2,NULL);
    pthread_cond_init(&cond2,NULL);

    pthread_t pthid1;
    pthread_t pthid2;
    pthread_create(&pthid1,NULL,func1,NULL);
    pthread_create(&pthid2,NULL,func2,NULL);

    pthread_join(pthid1,NULL);
    pthread_join(pthid2,NULL);

    return 0;
}

